#include<stdio.h>

int main(void)
{
	int num,real;
	
	scanf("%d",&num);
	
	int thou=0,han=0,ten=0,one=0;
	
	one=num%10;
	ten=num/10%10;
	han=num/100%10;
	thou=num/1000%10;
	
	if(one>4)
	{
		one--;
	}
	if(ten>4)
	{
		ten--;
	}
	if(han>4)
	{
		han--;
	}
	if(thou>4)
	{
		thou--;
	}
	
	printf("%d",thou*729+han*81+ten*9+one);
	
	return 0;
}
